package ltd.ninefish.framework.core.web.page;

import cn.hutool.core.convert.Convert;
import ltd.ninefish.framework.core.utils.spring.ServletUtil;

/**
 * @author zhaoxiubin
 * create-time 2023-12-16 15:19
 * description 分页信息处理类
 **/

public class PageInfoHandler {
    /**
     * 页码
     */
    public static final String PAGE_NUM = "pageNum";
    /**
     * 每页记录数
     */
    public static final String PAGE_SIZE = "pageSize";
    /**
     * 总记录数
     */
    public static final String TOTAL = "total";
    /**
     * 总页数
     */
    public static final String TOTAL_PAGE = "totalPage";
    /**
     * 排序字段
     */
    public static final String SORT_FIELD = "sortField";
    /**
     * 排序方式
     */
    public static final String SORT_BY = "sortBy";
    /**
     * 分页参数合理化
     */
    public static final String REASONABLE = "reasonable";

    /**
     * 封装分页对象
     */
    public static PageInfo getRequestPageInfo()
    {
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageNum(Convert.toInt(ServletUtil.getParameter(PAGE_NUM), 1));
        pageInfo.setPageSize(Convert.toInt(ServletUtil.getParameter(PAGE_SIZE), 10));
        pageInfo.setSortField(ServletUtil.getParameter(SORT_FIELD));
        pageInfo.setSortBy(ServletUtil.getParameter(SORT_BY));
        pageInfo.setReasonable(ServletUtil.getParameterToBool(REASONABLE));
        return pageInfo;
    }
}
